package com.farina.tracescleaner.tasks;

import java.io.File;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog;
import android.provider.CallLog.Calls;

public class DeleteCallLogTask{

	Context context;


	public DeleteCallLogTask(Context context) {
		this.context=context;
	}

	public void delete() {
		String queryString="MESSAGEID >= 0"; 
		context.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI, null, null);
		
		//context.getContentResolver().delete(Uri.parse("content://call_logs/calls?logtype=200"), null, null);
		try {
			String[] projection = new String[] {Calls._ID, CallLog.Calls.CACHED_NAME, CallLog.Calls.DATE, CallLog.Calls.DURATION, CallLog.Calls.NUMBER, CallLog.Calls.TYPE };

			Cursor cursor = context.getContentResolver().query(Calls.CONTENT_URI, projection , null, null, Calls.DATE + " DESC");
            boolean bol = cursor.moveToFirst();
            if (bol) {
                do {
                    int idOfRowToDelete = cursor.getInt(cursor.getColumnIndex(CallLog.Calls._ID));
                    context.getContentResolver().delete(Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, String.valueOf(idOfRowToDelete)), "", null);
                    System.out.print(cursor.getString(0));
                } while (cursor.moveToNext());
            }
        } catch (Exception ex) {
           ex.printStackTrace();
        }
	}


}
